package com.kagura.restdemo.controller;

import com.kagura.restdemo.pojo.User;
import com.kagura.restdemo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @PACKAGE_NAME: com.kagura.restdemo.controller
 * @CLASS_NAME: UserRestController
 * @USER: kagura
 * @Description TODO
 * @Date 2021/5/28 5:52 下午
 * @MONTH_NAME_FULL: 五月
 * @DAY: 28
 * @DAY_NAME_FULL: 星期五
 * @PROJECT_NAME: restDemo
 **/
@RestController
@RequestMapping(value = "/api/")
public class UserRestController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/user", method = RequestMethod.POST)
    public boolean addUser(@RequestBody User user) {
        return userService.addUser(user);
    }

    @RequestMapping(value = "/user", method = RequestMethod.PUT)
    public boolean updateUser(User user) {
        return userService.updateUser(user);
    }

    @RequestMapping(value = "/user", method = RequestMethod.DELETE)
    public boolean deleteUser(@RequestParam(value = "name", required = true) int userId) {
        return userService.deleteUser(userId);
    }

    @RequestMapping(value = "/user", method = RequestMethod.GET)
    public List<User> findUserByName(@RequestParam(value = "name", required = true) String userName) {
        return userService.findByName(userName);
    }

    @RequestMapping(value = "/userAll", method = RequestMethod.GET)
    public List<User> findAllUsers() {
        return userService.findAllUsers();
    }
}
